﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Services;
using System.Collections;
using System.Data;

namespace Catering.Catering_Page.Caipin
{
    public partial class shipu_left : UserIsNull
    {
        public DataTable dt_DishType = new DataTable();
        public DataTable dt_DishTypes = new DataTable();
        public DataTable dt_Dish = new DataTable();
        public DataTable dt_library = new DataTable();
        public string m_IsNew = "true";
        public string m_Edit = "false";

        protected void Page_Load(object sender, EventArgs e)
        {
            ViewState["DishList"] = new View_Operaction_Common().UITreeViewDataBind_DishTypes("1");
            if (Request.QueryString["IsNew"] != null)
            {
                m_IsNew = Request.QueryString["IsNew"].ToString();
                m_Edit = "true";
            }
            if (!IsPostBack)
            {
                this.LoadData();
            }
        }

        //加载页面数据
        public void LoadData()
        {
            this.dt_DishType = new Catering_Rules.DishType().GetAllList().Tables[0];
            this.dt_DishTypes = new Catering_Rules.DishTypes().GetAllList().Tables[0];
        }

        //加载菜
        public void LoadDish(string strTypes)
        {
            this.dt_Dish = new Catering_Rules.T_Dish().GetList("DTID=" + strTypes).Tables[0];
        }

        //加载菜谱库
        public void LoadLibrary()
        {
            if (Request.QueryString["cid"] == null)//食谱ID
                return;

            string cid = Request.QueryString["cid"].ToString();
            string tedianID = "";
            Catering_Model.E_Recipes md_R = new Catering_Rules.T_Recipes().GetModel(Convert.ToInt32(cid));
            if (Request.QueryString["IsGroupCatering"] != null)//群体配餐
            {
                Catering_Model.GroupCatering md_GC = new Catering_Rules.GroupCatering().GetModel(md_R.GroupID);
                tedianID = md_GC.temp2;
            }
            else
            {
                Catering_Model.PersonalService md_PS = new Catering_Rules.PersonalService().GetModel(md_R.PID);
                tedianID = md_PS.temp2;
            }

            this.dt_library = new Catering_Rules.library().GetList("temp1='" + tedianID + "'").Tables[0];
        }

        [WebMethod]
        public static ArrayList CaiPin_Info_Tedian(string Dish_ID)
        {
            ArrayList list = new ArrayList();
            Catering_Model.E_Dish md_Dish = new Catering_Rules.T_Dish().GetModel(Convert.ToInt32(Dish_ID));
            list.Add(md_Dish.Name);

            DataTable dt_DishInfo = new Catering_Rules.T_DishInfo().GetList("DID=" + Dish_ID).Tables[0];
            decimal reliang = 0;
            decimal danbaizhi = 0;
            decimal zhifang = 0;
            foreach (DataRow row in dt_DishInfo.Rows)
            {
                DataTable dt_NC = new Catering_Rules.NutrientComposition().GetList(24, "RawID=" + row["RawID"], "NutritionElementsID").Tables[0];
                reliang += Convert.ToDecimal(dt_NC.Select("NutritionElementsID=1")[0]["Content"].ToString().SetToString()) / 100 * Convert.ToDecimal(row["Content"].ToString());
                danbaizhi += Convert.ToDecimal(dt_NC.Select("NutritionElementsID=2")[0]["Content"].ToString().SetToString()) / 100 * Convert.ToDecimal(row["Content"].ToString());
                zhifang += Convert.ToDecimal(dt_NC.Select("NutritionElementsID=3")[0]["Content"].ToString().SetToString()) / 100 * Convert.ToDecimal(row["Content"].ToString());
            }
            list.Add(decimal.Round(reliang, 2).ToString());
            list.Add(decimal.Round(danbaizhi, 2).ToString());
            list.Add(decimal.Round(zhifang, 2).ToString());
            /*
            DataTable dt_DishNutrien = new Catering_Rules.DishNutrien().GetList("Dishid="+Dish_ID).Tables[0];
            list.Add(dt_DishNutrien.Select("fatherid='1'")[0]["Content"].ToString());//热量
            list.Add(dt_DishNutrien.Select("fatherid='2'")[0]["Content"].ToString());//蛋白质
            list.Add(dt_DishNutrien.Select("fatherid='3'")[0]["Content"].ToString());//脂肪
            */
            list.Add(md_Dish.Characteristic == null ? "无" : md_Dish.Characteristic);//特点
            return list;
        }
    }
}